package freespiritsocial.io.user.ui.adapter

import android.view.ViewGroup
import androidx.core.view.updateLayoutParams
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.scwang.smart.refresh.layout.util.SmartUtil.dp2px
import freespiritsocial.io.user.R
import freespiritsocial.io.user.data.model.bean.TagPojo
import freespiritsocial.io.user.databinding.ItemExploreFilterBinding
import freespiritsocial.io.user.viewmodel.ExploreViewModel

/**
 * 首页过滤适配器
 */
class ExploreFilterAdapter(
    val model: ExploreViewModel,
    data: ArrayList<TagPojo> = arrayListOf(),
    layoutResIdRes: Int = R.layout.item_explore_filter
):
    BaseQuickAdapter<TagPojo,BaseDataBindingHolder<ItemExploreFilterBinding>>(layoutResIdRes,data) {


    override fun convert(holder: BaseDataBindingHolder<ItemExploreFilterBinding>,item: TagPojo) = with(holder.dataBinding) {
        this?.root?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
            this.height = dp2px(if (item.tagName == model.tagName) 60f else 56f)
            this.width = dp2px(if (item.tagName == model.tagName) 116f else 108f)
            marginStart = dp2px(if (item.tagName == model.tagName) 0f else 5f)
            marginEnd = dp2px(if (item.tagName == model.tagName) 0f else 5f)
        }
        this?.tv?.textSize = if (item.tagName == model.tagName) 17f else 15f
        this?.name = item.tagName
        this?.image = item.backgroundImage
        this?.executePendingBindings()
        Unit
    }
}